package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;


    /**
     * 上架专辑
     * @param albumId
     * @return
     */
    @Operation(summary = "上架专辑")
    @GetMapping("/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable("albumId") Long albumId) {
        searchService.upperAlbum(albumId);
        return Result.ok();
    }

    /**
     * 下架专辑
     * @param albumId
     * @return
     */
    @Operation(summary = "下架专辑")
    @GetMapping("/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable("albumId") Long albumId) {
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }


    /**
     * 专辑搜索列表
     * @param albumIndexQuery
     * @return
     * http://127.0.0.1:8500/api/search/albumInfo
     */
    @Operation(summary = "专辑搜索列表")
    @PostMapping("/albumInfo")
    public Result search(@RequestBody AlbumIndexQuery albumIndexQuery){
        log.info("专辑搜索列表");
        AlbumSearchResponseVo albumSearchResponseVo = searchService.search(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }

}

